<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-search"
          size="mini"
          @click="handleSearch"
          >查询</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="flag"
          @click="finishBack"
          v-hasPermi="['output:cpmFinish:back']"
        >
          撤回
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          size="mini"
          :disabled="type1"
          @click="handleDelivery"
          v-hasPermi="['output:cpmFinish:oneClickOut']"
        >
          一键出库确认
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-circle-check"
          size="mini"
          :disabled="flag || loading"
          @click="handlePost"
          v-hasPermi="['output:cpmFinish:post']"
        >
          过账
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          @click="printHandle"
          v-hasPermi="['output:cpmFinish:print']"
        >
          单据打印
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['output:cpmStart:export']"
        >
          导出
        </el-button>
      </el-col>
      <HdTagGroup />
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <!--    需要打印的东西-->
    <el-dialog
      v-model="printDiag"
      :close-on-click-modal="false"
      width="1046px"
      append-to-body
    >
      <section ref="print">
        <el-table
          border
          style="width: 100%"
          :data="cpmMstrs"
          :header-cell-style="{ 'text-align': 'center' }"
        >
          <el-table-column label="武汉市衡德实业有限公司产品退货出库单">
            <el-table-column label="供应商" width="135">
              <el-table-column
                label="单据编号"
                align="center"
                prop="cpmDjbh"
                width="135"
              ></el-table-column>
              <el-table-column
                label="物料编码"
                align="center"
                prop="cpmWldm"
                width="135"
              ></el-table-column>
            </el-table-column>
            <el-table-column :label="printDjbh" width="135">
              <el-table-column
                label="物料名称规格"
                prop="itmPmgg"
                width="355"
              ></el-table-column>
            </el-table-column>
            <el-table-column :label="printRy" width="300">
              <el-table-column label="退货原因" prop="cpmThyy" width="120" />
              <el-table-column
                label="单位"
                :show-overflow-tooltip="true"
                width="60"
                align="center"
                prop="itmDw"
              >
                <template #default="scope">
                  <dict-tag
                    :options="unitFlagOptions"
                    :value="scope.row.itmDw"
                  />
                </template>
              </el-table-column>
            </el-table-column>
            <el-table-column :label="printRq" width="100">
              <el-table-column
                label="数量"
                align="center"
                prop="cpmCksl"
                width="80"
              ></el-table-column>
              <el-table-column label="备注" width="120"></el-table-column>
            </el-table-column>
          </el-table-column>
        </el-table>
        <div
          slot="footer"
          class="dialog-footer no-print"
          style="margin-top: 10px; display: flex; justify-content: flex-end"
        >
          <el-button type="primary" class="no-print" @click="printData"
            >打 印</el-button
          >
          <el-button class="no-print" @click="cancel">取 消</el-button>
        </div>
      </section>
    </el-dialog>

    <el-table
      @scrollBottom="load"
      highlight-current-row
      :height="tableH"
      border
      stripe
      v-loading="loading"
      :data="cpmStartList"
      :row-class-name="iCellStyle"
      @row-click="clickRow"
      @selection-change="handleSelectionChange"
      :header-cell-style="{ 'text-align': 'center' }"
    >
      <el-table-column label="#" width="40" type="index" align="center" />
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column
        label="退货单号"
        :show-overflow-tooltip="true"
        width="135"
        align="center"
        prop="cpmDjbh"
      />
      <el-table-column
        label="退货日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="cpmCtrq"
        width="150"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.cpmCtrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="退货班组"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="cpmCsdm"
      ></el-table-column>
      <el-table-column
        label="仓库"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="cpmCkdm"
      >
        <template #default="scope">
          <dict-tag :options="allStorageOptions" :value="scope.row.cpmCkdm" />
        </template>
      </el-table-column>
      <el-table-column
        label="撤回原因"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="cpmNgdesc"
      />
      <el-table-column
        label="退货状态"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="cpmZtbz"
      >
        <template #default="scope">
          <dict-tag :options="cpmZtbzOptions" :value="scope.row.cpmZtbz" />
        </template>
      </el-table-column>
      <el-table-column
        label="建立人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="cpmJlry"
      />
      <el-table-column
        label="建立日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="cpmJlrq"
        width="150"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.cpmJlrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="审核人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="cpmShry"
      />
      <el-table-column
        label="审核日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="cpmShrq"
        width="150"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.cpmShrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="批准人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="cpmPzry"
      />
      <el-table-column
        label="批准日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="cpmPzrq"
        width="150"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.cpmPzrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="过账人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="cpmGzry"
      />
      <el-table-column
        label="过账日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="cpmGzrq"
        width="150"
      >
        <template #default="scope">
          <span>{{ parseTime(scope.row.cpmGzrq, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
    </el-table>
    <!--明细-->
    <el-tabs v-model="activeTab">
      <el-tab-pane label="明细" name="first">
        <el-table
          border
          stripe
          :height="tableHAddChild"
          :data="cpdList"
          id="exportMx"
          :header-cell-style="{ 'text-align': 'center' }"
        >
          <el-table-column label="#" type="index" align="center" fixed="left" />
          <el-table-column
            label="物料代码"
            :show-overflow-tooltip="true"
            width="135"
            align="center"
            prop="cpdWldm"
          />
          <el-table-column
            label="品名规格"
            :show-overflow-tooltip="true"
            prop="itmPmgg"
          />
          <el-table-column
            label="单位"
            :show-overflow-tooltip="true"
            width="80"
            align="center"
            prop="itmDw"
          >
            <template #default="scope">
              <dict-tag :options="unitFlagOptions" :value="scope.row.itmDw" />
            </template>
          </el-table-column>
          <el-table-column
            label="申请数量"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="cpdSqsl"
          />
        </el-table>
      </el-tab-pane>
      <el-tab-pane label="领料统计" name="second">
        <el-table
          border
          :row-style="fnRowStyle"
          :height="tableHAddChild"
          :data="cpdListTotal"
        >
          <el-table-column
            label="物料代码"
            :show-overflow-tooltip="true"
            width="135"
            align="center"
            prop="cpdWldm"
          />
          <el-table-column
            label="品名规格"
            :show-overflow-tooltip="true"
            width="400"
            prop="itmPmgg"
          />
          <el-table-column
            label="单位"
            :show-overflow-tooltip="true"
            width="80"
            align="center"
            prop="itmDw"
          >
            <template #default="scope">
              <dict-tag :options="unitFlagOptions" :value="scope.row.itmDw" />
            </template>
          </el-table-column>
          <el-table-column
            label="申请数量"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="cpdSqsl"
          />
          <el-table-column
            label="出库数量"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="cpdCksl"
          />
          <el-table-column
            label="不良原因"
            :show-overflow-tooltip="true"
            align="center"
            prop="cpdBlyy"
          />
          <el-table-column
            label="操作"
            align="center"
            width="65"
            class-name="small-padding fixed-width"
          >
            <template #default="scope">
              <div
                class="delectButton"
                :disabled="type1"
                @click="handleConfirm(scope.row)"
                v-hasPermi="['output:cpmFinish:outputConfirm']"
              >
                出库确认
              </div>
            </template>
          </el-table-column>
        </el-table>
      </el-tab-pane>
    </el-tabs>
    <!-- 查询对话框   -->
    <el-dialog
      :title="title"
      v-model="openSearch"
      :close-on-click-modal="false"
      draggable
      width="680px"
      append-to-body
    >
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
        label-width="70px"
      >
        <el-col :span="12">
          <el-form-item label="退货单号" prop="cpmDjbh">
            <el-input
              v-model="queryParams.cpmDjbh"
              placeholder="请输入退货单号"
              clearable
              style="width: 240px"
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="物料代码" prop="cpmWldm">
            <el-input
              v-model="queryParams.cpmWldm"
              placeholder="请输入物料代码"
              clearable
              style="width: 240px"
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="开单日期">
            <el-date-picker
              v-model="daterangeCpmJlrq"
              size="small"
              :picker-options="pickerOptions"
              style="width: 240px"
              value-format="yyyy-MM-dd HH:mm:ss"
              :default-time="['00:00:00', '23:59:59']"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item>
            <RadioGroup v-model="queryParams.cpmZtbz">
              <Radio label="11" style="margin: 0px 30px">未审核</Radio>
              <Radio label="12" style="margin-right: 30px">已审核</Radio>
              <Radio label="10" align="right">全部</Radio>
            </RadioGroup>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="规格描述" prop="itmPmgg">
            <el-input
              v-model="queryParams.itmPmgg"
              placeholder="请输入规格描述"
              clearable
              style="width: 560px"
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item
            style="margin-top: 25px; display: flex; justify-content: flex-end"
          >
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" @click="handleQuery">确认</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>
    <!-- 出库确认对话框   -->
    <el-dialog
      :title="title"
      v-model="resultOpen"
      :close-on-click-modal="false"
      draggable
      width="650px"
      append-to-body
    >
      <el-form
        ref="cfdForm"
        :model="cfdForm"
        label-width="88px"
        :rules="cfdFormRules"
      >
        <el-col :span="24">
          <el-form-item label="品名规格" prop="itmPmgg">
            <el-input v-model="cfdForm.itmPmgg" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="物料代码" prop="cpdWldm">
            <el-input v-model="cfdForm.cpdWldm" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="申请数量" prop="cpdSqsl">
            <el-input v-model="cfdForm.cpdSqsl" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="单位" prop="itmDw">
            <dict-tag :options="unitFlagOptions" :value="cfdForm.itmDw" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="出库数量" prop="cpdCksl">
            <el-input v-model="cfdForm.cpdCksl" type="number" />
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="ckSubmit">确 定</el-button>
        <el-button @click="resultOpen = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  listCpmStart,
  finishBackCpm,
  postCpm,
  exportCpmStart,
  getCpmStartDetail,
  oneClickOut,
  outputConfirm,
} from "@/api/output/cpm";
import { getAllCs } from "@/api/putStorage/putStorageAdd";
import { getAll } from "@/api/repertory/Storage";
import { printOrder } from "@/utils/ruoyi";

export default {
  name: "CpmFinish",
  data() {
    return {
      //表格高度
      tableH: 250,
      tableHChild: 300,
      tableHAdd: 250,
      tableHAddChild: 300,
      cpdList: [],
      cpdListTotal: [],
      openChild: false,
      serachAddList: [],
      total2: 0,
      activeTab: "second",
      type1: true,
      resultOpen: false,
      cfdFormRules: {
        cpdCksl: [
          { required: true, message: "请输入出库数量", trigger: "blur" },
        ],
      },
      cfdForm: {},
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      cpmDjbhs: [],
      //选中的数据
      cpmMstrs: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      openSearch: false,
      //单位字典
      unitFlagOptions: [],
      //存放位置
      allCwOptions: [],
      // 退货状态字典
      cpmZtbzOptions: [
        { dictValue: "1", dictLabel: "新增", listClass: "default" },
        { dictValue: "2", dictLabel: "审核", listClass: "default" },
        { dictValue: "3", dictLabel: "批准", listClass: "default" },
        { dictValue: "6", dictLabel: "过账", listClass: "default" },
      ],
      //退货日期
      cpmThrq: new Date(),
      //存储厂商
      allCsOptions: [],
      //退货厂商
      cpmThCs: null,
      //退货厂商单号
      vCpmDjbhs: [],
      // 总条数
      total: 0,
      // 退货出库表格数据
      cpmStartList: [],
      allStorageOptions: [],
      //保存当前行数据
      rhmData: null,
      printDjbh: null,
      printRq: null,
      printCkdm: null,
      printDh: null,
      printRy: null,
      flag: true,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      printDiag: false,
      // 是否显示厂商确认
      vConfirmOpen: false,
      // 建立日期时间范围
      daterangeCpmJlrq: [
        this.$moment().startOf("month").toDate(),
        this.$moment().add(100, "year").endOf("month").toDate(),
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 40,
        cpmDjbh: null,
        cpmWldm: null,
        cpmJlrq: null,
        itmPmgg: null,
        cpmZtbz: "11",
      },
      // 表单参数
      form: {},
      //日期初始化
      pickerOptions: {
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
    };
  },
  created() {
    //单位
    this.getDicts("sys_unit").then((response) => {
      this.unitFlagOptions = response.data;
    });
    getAll().then((response) => {
      this.allStorageOptions = response.data;

      for (let item of this.allStorageOptions) {
        item.dictLabel = item.storageName;
        item.listClass = "default";
        item.dictValue = item.storageId + "";
      }
    });
    getAll().then((response) => {
      this.allCwOptions = response.data;

      for (let item2 of this.allCwOptions) {
        item2.dictLabel = item2.storageDefaultstorage;

        item2.listClass = "default";
        item2.dictValue = item2.storageId + "";
      }
    });

    getAllCs().then((response) => {
      this.allCsOptions = response.data;
      for (let item of this.allCsOptions) {
        item.dictLabel = item.csmCsmc;
        item.listClass = "default";
        item.dictValue = item.csmCsdm;
      }
    });
    this.getList();
  },
  methods: {
    /** 颜色事件 */
    iCellStyle({ row }) {
      //提交
      if (row.cpmZtbz == "1" && row.cpmTjflag == "1") {
        return "submit";
      }
      //审核
      else if (row.cpmZtbz == "2" && row.cpmTjflag == "1") {
        return "check";
      }
      //批准
      else if (row.cpmZtbz == "4" && row.cpmTjflag == "1") {
        return "permit";
      }
      //过账
      else if (row.cpmZtbz == "6" && row.cpmTjflag == "1") {
        return "past";
      }
    },
    /** 查询退货出库列表 */
    getList(row) {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeCpmJlrq && "" != this.daterangeCpmJlrq) {
        this.queryParams.params["beginCpmJlrq"] = this.moment(
          this.daterangeCpmJlrq[0]
        ).format("YYYY-MM-DD HH:mm:ss");
        this.queryParams.params["endCpmJlrq"] = this.moment(
          this.daterangeCpmJlrq[1]
        ).format("YYYY-MM-DD HH:mm:ss");
      }
      this.queryParams.pageNum = 1;
      listCpmStart(this.queryParams).then((response) => {
        this.cpmStartList = response.rows;
        this.total = response.total;
        this.loading = false;
        if (row != null) {
          this.clickRow(row);
        } else if (this.cpmStartList != null && this.cpmStartList.length > 0) {
          this.clickRow(this.cpmStartList[0]);
        } else {
          this.type1 = true;
        }
      });
    },
    //load
    load() {
      if (
        this.queryParams.pageNum <
        Math.ceil(this.total / this.queryParams.pageSize)
      ) {
        this.queryParams.pageSize = 40;
        this.queryParams.pageNum++;
        listCpmStart(this.queryParams).then((response) => {
          this.cpmStartList = this.cpmStartList.concat(response.rows);
          this.total = response.total;
        });
      }
      return 0;
    },
    printData() {
      this.$print(this.$refs.print).dom.ownerDocument.title =
        "武汉市衡德实业有限公司";
      // console.log( this.$print(this.$refs.print))
    },
    printHandle() {
      // const csName = []
      // for (let i = 0; i < this.cpmMstrs.length; i++) {
      //   csName.push(this.cpmMstrs[i].cpmCsdm)
      // }
      // var b = [...new Set(csName)]
      // if (b.length > 1) {
      //   this.msgError('请选择退货厂商一致的~')
      //   return 0
      // }
      printOrder(
        "/output/cpm/exportCpmFinishTemplate",
        this.rowData,
        "成品不良退库单据"
      );
    },
    //获取当前日期
    getdate() {
      var date = new Date();
      var seperator1 = "-";
      var year = date.getFullYear();
      var month = date.getMonth() + 1;
      var strDate = date.getDate();

      if (month >= 1 && month <= 9) {
        month = "0" + month;
      }
      if (strDate >= 0 && strDate <= 9) {
        strDate = "0" + strDate;
      }
      var currentdate = year + " 年 " + month + " 月 " + strDate + " 日 ";
      return currentdate;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openSearch = false;
      this.printDiag = false;
      this.reset();
    },
    //厂商确认重置
    resetConfirm() {
      this.vCpmDjbhs = [];
      this.cpmThrq = new Date();
      this.cpmThCs = null;
    },
    // 表单重置
    reset() {
      this.form = {
        cpmId: null,
        cpmDjbh: null,
        cpmCtrq: null,
        cpmCsdm: null,
        cpmWldm: null,
        cpmCwdm: null,
        cpmCksl: null,
        cpmThyy: null,
        cpmNgdesc: null,
        cpmTjflag: null,
        cpmZtbz: null,
        cpmJlry: null,
        cpmJlrq: null,
        cpmShry: null,
        cpmShrq: null,
        cpmPzry: null,
        cpmPzrq: null,
        cpmGzry: null,
        cpmGzrq: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.cpmStartList = [];
      this.getList();
      this.openSearch = false;
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCpmJlrq = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.cpmDjbhs = selection.map((item) => item.cpmDjbh);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
      this.cpmMstrs = selection;
    },
    handleSearch() {
      this.reset();
      this.title = "查询退货出库";
      this.openSearch = true;
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      exportCpmStart(queryParams)
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
    //检验状态
    check_state() {
      for (let i of this.cpmMstrs) {
        if (i.cpmZtbz != 4 || i.cpmTjflag != 1) {
          return true;
        }
      }
      return false;
    },
    //单据打印
    handlePrint() {
      this.printDiag = true;
    },
    //过账单据
    handlePost() {
      if (this.rowData.cpmZtbz != 4) {
        this.msgError("选中的单据不是过账状态,无法进行过账");
      } else {
        this.loading = true;
        postCpm(this.rowData)
          .then((res) => {
            this.getList();
            this.msgSuccess("过账成功");
            this.loading = false;
            this.rowData = {};
          })
          .catch(() => {
            this.msgError("过账单据失败~");
            this.loading = false;
          });
      }
    },
    //撤回单据
    finishBack() {
      if (this.check_state()) {
        this.msgError("选中的单据不是未过账状态,无法进行撤回");
      } else {
        finishBackCpm(this.rowData.cpmDjbh)
          .then((res) => {
            this.getList();
            this.msgSuccess("撤回成功");
          })
          .catch(() => {
            this.msgError("撤回单据失败~");
          });
      }
    },
    // 获取明细
    getRowDetList(order) {
      getCpmStartDetail(order).then((response) => {
        this.cpdList = response.data.list;
        this.cpdListTotal = response.data.total;
        this.mxDate = this.cpdList.length > 0 ? false : true;
      });
    },

    clickRow(row) {
      if (row) {
        this.flag = row.cpmZtbz != 4;
      }
      // //获得选中的详细数据
      this.rowData = row;
      // //获得当前单据的状态
      this.id = row.cpmId;
      this.type1 = !(row != null && row.cpmZtbz == "4" && row.cpmTjflag == "1");
      //获得选中的详细数据
      this.getRowDetList(row.cpmDjbh);
    },
    handleDelivery() {
      if (this.cpdList == null || this.cpdList.length === 0) {
        this.msgError("该单据无明细");
      } else {
        this.$confirm("是否进行一键出库确认作业?", "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            return oneClickOut(this.rowData.cpmDjbh);
          })
          .then((response) => {
            this.msgSuccess("检验成功");
            this.getChild(this.nowData);
          })
          .catch(() => {});
      }
    },
    handleConfirm(row) {
      this.cfdForm = row;
      this.title = "出库确认";
      this.resultOpen = true;
    },
    ckSubmit() {
      this.$refs["cfdForm"].validate((valid) => {
        if (valid) {
          outputConfirm(
            this.rowData.cpmDjbh,
            this.cfdForm.cpdWldm,
            this.cfdForm.cpdCksl
          ).then((response) => {
            this.resultOpen = false;
            this.getRowDetList(this.rowData.cpmDjbh);
          });
        }
      });
    },
    fnRowStyle({ row }) {
      if (row.cpdCksl) {
        return { color: "red" };
      }
    },
  },
};
</script>
<style lang="scss" scoped>
.inputName > .el-input__inner {
  height: 20px;
  line-height: 20px;
}
</style>
